// https://www.bilibili.com/video/BV11E411o7Fb?p=4
#include <bits/stdc++.h>
using namespace std;

int n;
vector<vector<int>> edges;
vector<bool> visited;

void dataInput(int& n,vector<vector<int>>& edges,vector<bool>& visited);
template <typename T>
void printVector(vector<T> nums);

//无向图
vector<int> bfs(int startNode){
    queue<int> q;
    q.push(startNode);
    visited[startNode] = true;
    vector<int> prev(visited.size(),-1);

    while(!q.empty()){
        int curNode = q.front();
        q.pop();
        vector<int> neighbours = edges[curNode];
        for(auto neighbour:neighbours){
            if(!visited[neighbour]){
                q.push(neighbour);
                visited[neighbour] = true;
                prev[neighbour] = curNode;
            }
        }
    }
    return prev;
}
int main(){
    //initial the grap;
    dataInput(n,edges,visited);
    printVector(bfs(0));
}



void dataInput(int& n,vector<vector<int>>& edges,vector<bool>& visited){
    cin >> n ;
    edges.resize(n);
    visited.resize(n);
    for(int i = 0; i< n; i++){
        int len;
        cin >>len;
        for(int j =0; j < len;j ++)
        {
            int value;
            cin >> value;
            edges[i].push_back(value);
        }
    }
}

template <typename T>
void printVector(vector<T> nums)
{
    for (auto n : nums)
    {
        cout << n << ' ';
    }
}
